// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Rollup;

public sealed partial class DateHistogramGrouping
{
	/// <summary>
	/// <para>
	/// The interval of time buckets to be generated when rolling up.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("calendar_interval")]
	public Elastic.Clients.Elasticsearch.Duration? CalendarInterval { get; set; }

	/// <summary>
	/// <para>
	/// How long to wait before rolling up new documents.
	/// By default, the indexer attempts to roll up all data that is available.
	/// However, it is not uncommon for data to arrive out of order.
	/// The indexer is unable to deal with data that arrives after a time-span has been rolled up.
	/// You need to specify a delay that matches the longest period of time you expect out-of-order data to arrive.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("delay")]
	public Elastic.Clients.Elasticsearch.Duration? Delay { get; set; }

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Field Field { get; set; }

	/// <summary>
	/// <para>
	/// The interval of time buckets to be generated when rolling up.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("fixed_interval")]
	public Elastic.Clients.Elasticsearch.Duration? FixedInterval { get; set; }
	[JsonInclude, JsonPropertyName("format")]
	public string? Format { get; set; }
	[JsonInclude, JsonPropertyName("interval")]
	public Elastic.Clients.Elasticsearch.Duration? Interval { get; set; }

	/// <summary>
	/// <para>
	/// Defines what <c>time_zone</c> the rollup documents are stored as.
	/// Unlike raw data, which can shift timezones on the fly, rolled documents have to be stored with a specific timezone.
	/// By default, rollup documents are stored in <c>UTC</c>.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("time_zone")]
	public string? TimeZone { get; set; }
}

public sealed partial class DateHistogramGroupingDescriptor<TDocument> : SerializableDescriptor<DateHistogramGroupingDescriptor<TDocument>>
{
	internal DateHistogramGroupingDescriptor(Action<DateHistogramGroupingDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DateHistogramGroupingDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Duration? CalendarIntervalValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? DelayValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? FixedIntervalValue { get; set; }
	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? IntervalValue { get; set; }
	private string? TimeZoneValue { get; set; }

	/// <summary>
	/// <para>
	/// The interval of time buckets to be generated when rolling up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> CalendarInterval(Elastic.Clients.Elasticsearch.Duration? calendarInterval)
	{
		CalendarIntervalValue = calendarInterval;
		return Self;
	}

	/// <summary>
	/// <para>
	/// How long to wait before rolling up new documents.
	/// By default, the indexer attempts to roll up all data that is available.
	/// However, it is not uncommon for data to arrive out of order.
	/// The indexer is unable to deal with data that arrives after a time-span has been rolled up.
	/// You need to specify a delay that matches the longest period of time you expect out-of-order data to arrive.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> Delay(Elastic.Clients.Elasticsearch.Duration? delay)
	{
		DelayValue = delay;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The interval of time buckets to be generated when rolling up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> FixedInterval(Elastic.Clients.Elasticsearch.Duration? fixedInterval)
	{
		FixedIntervalValue = fixedInterval;
		return Self;
	}

	public DateHistogramGroupingDescriptor<TDocument> Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	public DateHistogramGroupingDescriptor<TDocument> Interval(Elastic.Clients.Elasticsearch.Duration? interval)
	{
		IntervalValue = interval;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Defines what <c>time_zone</c> the rollup documents are stored as.
	/// Unlike raw data, which can shift timezones on the fly, rolled documents have to be stored with a specific timezone.
	/// By default, rollup documents are stored in <c>UTC</c>.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor<TDocument> TimeZone(string? timeZone)
	{
		TimeZoneValue = timeZone;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CalendarIntervalValue is not null)
		{
			writer.WritePropertyName("calendar_interval");
			JsonSerializer.Serialize(writer, CalendarIntervalValue, options);
		}

		if (DelayValue is not null)
		{
			writer.WritePropertyName("delay");
			JsonSerializer.Serialize(writer, DelayValue, options);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (FixedIntervalValue is not null)
		{
			writer.WritePropertyName("fixed_interval");
			JsonSerializer.Serialize(writer, FixedIntervalValue, options);
		}

		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (IntervalValue is not null)
		{
			writer.WritePropertyName("interval");
			JsonSerializer.Serialize(writer, IntervalValue, options);
		}

		if (!string.IsNullOrEmpty(TimeZoneValue))
		{
			writer.WritePropertyName("time_zone");
			writer.WriteStringValue(TimeZoneValue);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class DateHistogramGroupingDescriptor : SerializableDescriptor<DateHistogramGroupingDescriptor>
{
	internal DateHistogramGroupingDescriptor(Action<DateHistogramGroupingDescriptor> configure) => configure.Invoke(this);

	public DateHistogramGroupingDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Duration? CalendarIntervalValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? DelayValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? FixedIntervalValue { get; set; }
	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? IntervalValue { get; set; }
	private string? TimeZoneValue { get; set; }

	/// <summary>
	/// <para>
	/// The interval of time buckets to be generated when rolling up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor CalendarInterval(Elastic.Clients.Elasticsearch.Duration? calendarInterval)
	{
		CalendarIntervalValue = calendarInterval;
		return Self;
	}

	/// <summary>
	/// <para>
	/// How long to wait before rolling up new documents.
	/// By default, the indexer attempts to roll up all data that is available.
	/// However, it is not uncommon for data to arrive out of order.
	/// The indexer is unable to deal with data that arrives after a time-span has been rolled up.
	/// You need to specify a delay that matches the longest period of time you expect out-of-order data to arrive.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor Delay(Elastic.Clients.Elasticsearch.Duration? delay)
	{
		DelayValue = delay;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor Field(Elastic.Clients.Elasticsearch.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The date field that is to be rolled up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The interval of time buckets to be generated when rolling up.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor FixedInterval(Elastic.Clients.Elasticsearch.Duration? fixedInterval)
	{
		FixedIntervalValue = fixedInterval;
		return Self;
	}

	public DateHistogramGroupingDescriptor Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	public DateHistogramGroupingDescriptor Interval(Elastic.Clients.Elasticsearch.Duration? interval)
	{
		IntervalValue = interval;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Defines what <c>time_zone</c> the rollup documents are stored as.
	/// Unlike raw data, which can shift timezones on the fly, rolled documents have to be stored with a specific timezone.
	/// By default, rollup documents are stored in <c>UTC</c>.
	/// </para>
	/// </summary>
	public DateHistogramGroupingDescriptor TimeZone(string? timeZone)
	{
		TimeZoneValue = timeZone;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CalendarIntervalValue is not null)
		{
			writer.WritePropertyName("calendar_interval");
			JsonSerializer.Serialize(writer, CalendarIntervalValue, options);
		}

		if (DelayValue is not null)
		{
			writer.WritePropertyName("delay");
			JsonSerializer.Serialize(writer, DelayValue, options);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (FixedIntervalValue is not null)
		{
			writer.WritePropertyName("fixed_interval");
			JsonSerializer.Serialize(writer, FixedIntervalValue, options);
		}

		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (IntervalValue is not null)
		{
			writer.WritePropertyName("interval");
			JsonSerializer.Serialize(writer, IntervalValue, options);
		}

		if (!string.IsNullOrEmpty(TimeZoneValue))
		{
			writer.WritePropertyName("time_zone");
			writer.WriteStringValue(TimeZoneValue);
		}

		writer.WriteEndObject();
	}
}